package com.example.pinkcat.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.example.pinkcat.R;
import com.example.pinkcat.activity.adapter.PCA_recyleview_adapter;


import java.util.Objects;

public class PinCatAgreement extends AppCompatActivity {
    Context context=this;
    TextView agreementTitleView;

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        if (newConfig.fontScale != 1)//非默认值
            getResources();
        super.onConfigurationChanged(newConfig);
    }

    @Override
    public Resources getResources() {
        Resources res = super.getResources();
        if (res.getConfiguration().fontScale != 1) {//非默认值
            Configuration newConfig = new Configuration();
            newConfig.setToDefaults();//设置默认
            res.updateConfiguration(newConfig, res.getDisplayMetrics());
        }
        return res;
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        //初始化
        super.onCreate(savedInstanceState);
        Objects.requireNonNull(getSupportActionBar()).hide();//去掉标题栏
//        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
//                WindowManager.LayoutParams.FLAG_FULLSCREEN);//去掉信息栏
        setContentView(R.layout.activity_pin_cat_agreement);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN| View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }//深色信息栏

        //获取元素
        agreementTitleView=findViewById(R.id.agreement_title);


        //代码块
        Intent intent=getIntent();
        String agreementTitle="ss";
        if (intent!=null){
            agreementTitle=intent.getStringExtra("agreementTitle");
        }
        if (agreementTitle==null) agreementTitle="ss";
        RecyclerView recyclerView=findViewById(R.id.agreement_txt);
        recyclerView.setLayoutManager(new LinearLayoutManager(context));
        PCA_recyleview_adapter adapter;
        if (agreementTitle.equals("隐私协议")){
            agreementTitleView.setText(agreementTitle);
            adapter=new PCA_recyleview_adapter(context,1,true);
        }
        else if (agreementTitle.equals("用户协议")){
            agreementTitleView.setText(agreementTitle);
            adapter=new PCA_recyleview_adapter(context,1,false);
        }
        else {
            adapter=new PCA_recyleview_adapter(context,1,true);
        }

        recyclerView.setAdapter(adapter);


        findViewById(R.id.back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
    }
}